/**
 * @FilePath     : /src/lgmg_robots/agv_navigation/agv_navigate/include/agvNavigate/work_code.h
 * @Description  : 工作码类型及其相关的类和结构，主要用于任务管理和状态指示。 
 *                 WorkCode类用于存储工作码，包含类型、指针和任务标志等信息。 
 * @Author       : xiujun.yang
 * @Version      : 1.0.0
 * @LastEditors  : haibo haibo.yang@lgmgim.cn
 * @LastEditTime : 2024-12-19 15:49:27
 * @Copyright (c) 2024 by 临工智能信息科技有限公司, All Rights Reserved. 
**/

#pragma once

#include "z_types.h"

// Work code type enums
enum class WorkCodeType {
    NO_WORKCODE = 0,
    NV_WORKCODE = 1,
    OP_WORKCODE = 2,
    DYN_WORKCODE = 3
};

// Task status 
constexpr UCHAR NORMAL_WORKCODE = 0;
constexpr UCHAR START_WORKCODE = 1 << 0;
constexpr UCHAR END_WORKCODE = 1 << 1;


//////////////////////////////////////////////////////////////////////////////
// The class that stores a "Work code".
class WorkCode
{
 public:	
	WorkCode(WorkCodeType type = WorkCodeType::NO_WORKCODE, DWORD pointer = 0, UCHAR task_flag = NORMAL_WORKCODE)
        : type_(type), pointer_(pointer), task_flag_(task_flag) {}
	
	void Nullify() {
		type_ = WorkCodeType::NO_WORKCODE;
		pointer_ = 0;
		task_flag_ = NORMAL_WORKCODE;
	}
	
	BOOL IsExecutable() {
        return (type_ == WorkCodeType::NV_WORKCODE || type_ == WorkCodeType::OP_WORKCODE || type_ == WorkCodeType::DYN_WORKCODE);
	}
	
	BOOL IsStartOfTask() { return (task_flag_ & START_WORKCODE) != 0; }
	BOOL IsEndOfTask() { return (task_flag_ & END_WORKCODE) != 0; }
 public:
	WorkCodeType type_;            // 0-None; 1-Navigation code; 2-Operation code; 3-Dynamic code
	DWORD pointer_;                // Pointer to the relevent object
	UCHAR task_flag_;              // 0 - normal; 1 - Start of task; 2 - end of task
};

//new add CTaskID
struct TaskId {
    int64_t task_id;     // Task identifier
    uint16_t subtask_id; // Subtask identifier
};